package com.chixing.controller;


import com.chixing.pojo.Cart;
import com.chixing.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class GetListCartController {



    @Autowired
    private CartService cartService;


    @GetMapping("cart")
    public ModelAndView getAll(){
        List<Cart> cartList = cartService.getAll();
        ModelAndView mav = new ModelAndView();
        mav.addObject("cartList",cartList);
        //mav.setViewName("product/list");     //   cart/list.jsp
        return mav;
    }

    @GetMapping("cart/{id}")
    public ModelAndView getById(@PathVariable("id") Integer cartId){
         Cart  cart = cartService.getById(cartId);
        ModelAndView mav = new ModelAndView();
        mav.addObject("cart",cart);
        mav.setViewName("product/payOrder");// cart/payOrder.jsp
        return mav;
    }
}
